<!doctype html>
<html>
  <head>
  <link rel="icon" 
      type="image/png" 
      href="../favicon.png">
  <title>fasttimesheet - admin page</title>
  	<meta http-equiv="content-type" content=""text/htm; charset=UTF-8" >
	<link href="default.css" rel="stylesheet" type="text/css">
     <script type="text/javascript" src="../jquery/jquery.js"></script>
    
    
	<link href="../jquery/jquery-ui.css" rel="stylesheet" type="text/css"/>
  	<script src="../jquery/jquery-ui.min.js"></script>
  	
  	
 <link rel="stylesheet" href="../jquery-ui-1.8.4.custom.css" type="text/css" />
<link rel="stylesheet" href="../jquery/jquery.autocomplete.css" type="text/css" />
  <script type="text/javascript" src="../jquery/jquery.bgiframe.min.js"></script>
  
  <script type="text/javascript" src="../jquery/jquery.autocomplete.js"></script>  	
  	<script type="text/javascript" src="../jquery/jquery.jeditable.js"></script>
  	
  	
  	
  	
  
    <script type="text/javascript">
     
    </script>
  </head>
  <body>
  <style type="text/css">
	.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
	</style>
<script>

var shown=new Array();


function enabledisable(id,action) {
	//alert(action);
	$.post("../core/enabledisableadmin.php",{ 
  			action: action,
  			id: id
  			}, 
  		function(data){
  			gettree();
 			});	
}

function getselecttree() {
$.post("../visual/treecaller.php", function(data){
   $('#tree2').html(data);
   //treeaccordeon();
   selectanimate();
 });
}
function gettree() {
$.post("../visual/admintreecaller.php", function(data){
   $('#tree').html(data);
   showshown();
   $('.editjob').editable('../core/editclientadmin.php',{
   	style: "inherit", 
   	tooltip   : 'Click to edit',
   	callback: function(value,settings) {gettree();}
   	});
   $('.addsub').editable('../core/addclientadmin.php',{
   	style: "inherit", 
   	placeholder   : "Click to add subjob...",
   	callback: function(value,settings) {gettree();}
   	});
 });
}

function toggletree(id) {
	//alert($("#"+id).is(":hidden"));
	 
	 if ($("#"+id).is(':visible')) {
	 $("#"+id).hide(500);
	 delete shown["#"+id];
	 }
	 if ($("#"+id).is(':hidden')) {
	 $("#"+id).show(500);
	 shown["#"+id]="#"+id;
	 }
	 //hidehidden();
	
}

function showshown() {
	selects="";
	for ( var i in shown )
		{
    		selects=selects+",";
    		selects=selects+shown[i];
		}
	$(selects).show();
}

function list_users() {
	$.post("../core/listusersadmin.php", 
  		function(data){
   			$("#showusr").html(data);
   			$('.editusername').editable('../core/editusername.php',{
   				style: "inherit", 
   				tooltip   : 'Click to edit',
   				callback: function(value,settings) {list_users();}
   				});
   			$('.edituserlogin').editable('../core/edituserlogin.php',{
   				style: "inherit", 
   				tooltip   : 'Click to edit',
   				callback: function(value,settings) {list_users();}
   				});
   				
   			$('.edituserrole').editable('../core/edituserrole.php',{
   				style: "inherit", 
   				tooltip   : 'Click to edit',
   				data   : " {'0':'admin','1':'account','2':'user','3':'part-time', 'selected':'1'}",
     				type   : 'select',
     				submit : 'OK',
   				callback: function(value,settings) {list_users();}
   				});
   			$('.changepasswd').editable('../core/changeuserpasswd.php',{
   				style: "inherit", 
   				tooltip   : 'Click to change user password',
   				placeholder: 'Click to change user password',
   				callback: function(value,settings) {list_users(); $("#info").html(value);errordialog();}
   				});
   			userlit();
 			});	
}

function userlit() {
$(".userrow").hover(function() {
		//alert('lol');
  		$(this).addClass('rowlit_user');
  		//$(this).animate({ backgroundColor: "green", opacity: 0.85 }, 50);
		}, function() {
  		$(this).removeClass('rowlit_user');
		});
}

function unshow(login,ID) {
$.post("../core/removeuserfromnode.php",{ 
  			username: login,
  			ID: ID
  			}, 
  		function(data){
   			editnodes(login);
 			});

}


function showu(login,ID) {
$.post("../core/addusertonodenode.php",{ 
  			username: login,
  			ID: ID
  			}, 
  		function(data){
   			editnodes(login);
 			});

}


function editnodes(username) {
$.post("../visual/setusernodes.php",{ 
  			username: username
  			}, 
  		function(data){
   			$('#usernodes').html(data);
   			$("#usernodes").dialog({
			modal: true,
			minWidth: 400,
			height: 400,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
 			});
}

function enabledisableuser(id,action) {
		$.post("../core/enabledisableuser.php",{id: id,action: action},function(data) {list_users();});
	}



function errordialog() {
	if ($("#info").html() != "") {
	//alert ();
	$("#info").dialog({
			modal: true,
			minWidth: 400,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
	}
}

function adduser() {
		$.post("../core/adduser.php",$("#useradd").serialize(),function(data) {$("#info").html(data);resetuserform();errordialog();list_users();
		
		});
	}
function resetuserform() {
//alert('lol');
var a="";
$("#name").val('');
$("#login").val('');
$("#email").val('');
$("#passw1").val('');
$("#passw2").val('');


}

function user_dialog() {
	$("#addusr_form").dialog({
			modal: true,
			minWidth: 400,
			buttons: {
				Ok: function() {
					adduser();
					$(this).dialog('close');
				},
				Cancel: function() {
					
					$(this).dialog('close');
					resetuserform();
				}
				
			}
		});
	}
function movenode() {
		$.post("../core/movenodeadmin.php",$("#mvnod").serialize(),function(data) {$("#info").html(data);errordialog();gettree();getselecttree();
	});
	}
	
function selectanimate() {
	$(".hovertoggle").click(function() {
		$(".hovertoggle").animate({ backgroundColor: "#b2aeae", opacity: 0.75 }, 100);
		$(this).animate({ backgroundColor: "#68BFEF", opacity: 0.7 }, 100);
		});
	//$(".hovertoggle").mouseleave(function() {
    	//	$(this).animate({ backgroundColor: "#b2aeae", opacity: 0.75 }, 100);
	//	});
	
	
	}
	
function setjob(id) {
	$("#where").val(id);
	}
	
function setwhat(id) {
	$("#what").val(id);
	getselecttree();
	$("#node_move").dialog({
			modal: true,
			minWidth: 400,
			height:400,
			buttons: {
				Ok: function() {
					movenode();
					$(this).dialog('close');
				},
				Cancel: function() {
					$(this).dialog('close');
				}
				
			}
		});
	
	}

function attenddialog() {
	if ($("#attenddetails").html() != "") {
	//alert ();
	$("#attenddetails").dialog({
			modal: true,
			minWidth: 700,
			buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
		});
	}
}

function attend_details(uid,from,to) {
	$.post("../visual/attenddetails.php",{ 
  			uid: uid,
  			from: from,
  			to: to
  			}, 
  		function(data){
  			$("#attenddetails").html(data);
  			attenddialog();
 			});	
	}

$(document).ready(function(){
   gettree();
   //$('tree_hider').hide(1);
   
 });
 

function statistlit() {
	$(".statsok").hover(function() {
		//alert('lol');
  		$(this).addClass('rowlit');
  		//$(this).animate({ backgroundColor: "green", opacity: 0.85 }, 50);
		}, function() {
  		$(this).removeClass('rowlit');
		});
}

 
$(document).ready(function(){
   $('#add_master').click(function(){
   	$.post("../core/addmasteradmin.php",{ 
  			value: $('#addmaster').val(),
  			}, 
  		function(data){
   			gettree();
   			$('#addmaster').val("");
 			});	
   	
   	});
   
   
   
   
 });
 
 
 $(document).ready(function(){
 $("#datefrom").datepicker({ altFormat: 'yy-mm-dd' });
 $("#dateto").datepicker({ altFormat: 'yy-mm-dd' });
  });
  
$(document).ready(function(){
	 $('#simple_statistics').click(function(){
	 	$.post("../core/simplestatistics.php",{ 
  			datefrom: $('#datefrom').val(),
  			dateto: $('#dateto').val()
  			}, 
  		function(data){
   			$('#showstatistics').html(data);
   			statistlit();
 			});
	 });
}); 


$(document).ready(function(){
	
	list_users();
});

$(document).ready(function(){
	user_dialog
	$("#user_dialog").click(function(){user_dialog();});
	
});

$(document).ready(function(){
	$("#movenode").click(function(){movenode();});
});


$(document).ready(function(){
   $.post("../visual/treecaller.php", function(data){
   $('#tree2').html(data);
   //treeaccordeon();
   selectanimate();
 });
 });  
 
 $(document).ready(function() {
  	$('#loadinfo').hide();
  });

 $(document).ready(function() {
  	$('#loadinfo').ajaxStart(function() {
  	$(this).show();
  	//$(this).text('Loading');
  	//$(this).removeClass('loaded');
  	//$(this).addClass('loading');
	});
	
	$('#loadinfo').ajaxStop(function() {
	$(this).hide(50);
  	//$(this).text('Loaded');
  	//$(this).removeClass('loading');
  	//$(this).addClass('loaded');
	});
  });
  

$(document).ready(function() {
	$("#datefrom_daybyday").datepicker({ altFormat: 'yy-mm-dd' });
	$("#dateto_daybyday").datepicker({ altFormat: 'yy-mm-dd' });
		
	
	 $('#statistics_daybyday').click(function(){
	 	$.post("../core/daybydaystatistics.php",{ 
  			datefrom: $('#datefrom_daybyday').val(),
  			dateto: $('#dateto_daybyday').val(),
			userid: $("#userid_daybyday").val(),
			username: $("#userid_daybyday").val()
  			}, 
  		function(data){
   			$('#statistics_daybyday_show').html(data);

 			});
	 });


	});
</script>
<?php
$user=new core_user;


 if ($_SESSION['role'] < 2) {?>	  
<div class="maindiv" id="tree"></div>
<?php } ?>	  

<div id="right">
<div class="maindiv" id="loginfo"><p class="vertcenter"><?php echo $loc->logged_user;?>: <b><?php echo $user->getUserName($_SESSION['uid']);?> </b>
<br>
<form id="logoutform" action="index.php" method="POST">
<input type="submit" name="logout" value="log out" >
</form>
<?php if ($_SESSION['role'] < 2) {?>
<form id="logoutform" action="index.php" method="POST">
<input type="submit" name="page" value="statistics" >
<input type="submit" name="page" value="attendance" >
</form>
<?php } ?>
</p>
</div>
<div class="separator"></div>
<div class="maindiv" id="menu">

<?php if ($_SESSION['role'] < 2) {?>	  
<div class="maindiv" id="addmasternode">
<input type="text" name="addmaster" id="addmaster" value="">
<input type="button" name="add_master" id="add_master" value="<?php echo $loc->addmasternode;?>">

</div>

<?php } ?>
<div class="maindiv" id="info"></div>	 
</div>
<div class="separator"></div>
<div class="maindiv" id="simplestat">
<h3><?php echo $loc->checkattendanceall;?></h3>
<?php echo $loc->from2;?> <input type="text" id="datefrom" value=""> 
<?php echo $loc->to2;?> <input type="text" id="dateto" value="">
<p><input type="button" id="simple_statistics" value="<?php echo $loc->compute2;?>"</p>
<div class="insider"></div>
<div class="maindiv" id="showstatistics"></div>
</div>

<div class="separator"></div>
<div class="maindiv" id="simplestat">
<h3><?php echo $loc->daybydaystats;?></h3>
<?php echo $loc->from2;?> <input type="text" id="datefrom_daybyday"  value=""> 
<?php echo $loc->to2;?> <input type="text" id="dateto_daybyday"  value="">
<?php echo $loc->selectuser;?><select id="userid_daybyday">
<?php
$userquery="select id,name from users ORDER BY name";
$result=mysql_query($userquery);
while ($row=mysql_fetch_array($result)) {
	echo "<option id=".$row['id']." value=".$row['id']." >".$row['name']."</option>";
	}
?>

</select>
<p><input type="button" id="statistics_daybyday" value="<?php echo $loc->compute2;?>"</p>
<div class="insider"></div>
<div class="maindiv" id="statistics_daybyday_show"></div>
</div>

<div class="separator"></div>
<?php if ($_SESSION['role'] < 1) {?>	 
<div class="maindiv" id="usermanagement">
<h3>User management</h3>
<div id="showusr"></div>
<div class="insider"></div>

<div id="addusr">
<input type="button" name="user_dialog" id="user_dialog" value="Add user">
<div id="addusr_form" title="add user">
<form  id="useradd" action="" method="POST">
<p>name: <input type="text" value="" id="name" name="name"></p>
<p>login: <input type="text" value="" id="login" name="login"></p>
<p>email: <input type="text" value="" id="email" name="email"></p>
<p>role: <select name="role">
<option value="0">admin</option>
<option value="1">account</option>
<option value="2">user</option>
<option value="3">part-time</option>


</select></p>
<p>password: <input type="password" value="" id="passw1" name="passw1"></p>
<p>confirm password: <input type="password" value="" id="passw2" name="passw2"></p>
<input type="hidden" id="add_user" value="add user" name="add_user">
</form>
</div>
</div>
</div>
<?php } ?>
<?php if ($_SESSION['role'] <= 1) {?>	 
<div class="separator"></div>
<div class="maindiv" id="node_move" title="Select node to move to:">
<form id="mvnod"><input type="hidden" name="what" id="what" value=""><input type="hidden" name="where" id="where" value=""></form><input type="hidden" name="movenode" id="movenode" value="move">
<div id="tree2"></div>
</div>
<?php } ?>
<div class="maindiv" id="attenddetails" title="<?php echo $loc->attdetails;?>"></div>
<div class="maindiv" id="usernodes" title="user viewable nodes"></div>

<?php
require '../footer.php';
//echo date('m/d/Y');
?>

</div>
<div class="loaded" id="loadinfo"><table><tr><td><img src="loading.gif" alt="loading"></td> <td><span id="loadtext"> Loading </span></td></tr></table></div>
<?php
//echo date('m/d/Y');
?>

<script>
$("#sele").selectable();
</script>
</body>
</html>
